package com.kabuda.blog.controller;

import com.kabuda.blog.service.LoginService;
import com.kabuda.blog.service.RegisterService;
import com.kabuda.blog.service.SysUserService;
import com.kabuda.blog.vo.Result;
import com.kabuda.blog.vo.params.LoginParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author kabuda
 * @create 2023-01-17 11:03
 */
@Api(tags = "用户接口")
@RestController
@RequestMapping("")
public class UserController {
    @Autowired
    private SysUserService sysUserService;

    @Autowired
    LoginService loginService;

    @Autowired
    private RegisterService registerService;

    @ApiOperation("返回登录用户信息")
    @GetMapping("/users/currentUser")
    public Result currentUser(@RequestHeader("Authorization") String Authorization) {
        return sysUserService.currentUser(Authorization);
    }


    @ApiOperation("登录:生成返回token")
    @PostMapping
    @RequestMapping("/login")
    public Result login(@RequestBody LoginParams loginParams) {
        return loginService.login(loginParams);

    }


    @RequestMapping("logout")
    @ApiOperation("登出:删除redis中token信息")
    @GetMapping
    public Result logout(@RequestHeader("Authorization") String token) {
        return loginService.logout(token);
    }


    @RequestMapping("/register")
    @ApiOperation("注册")
    @PostMapping
    public Result register(@RequestBody LoginParams loginParams) {
        return registerService.register(loginParams);
    }


}
